<?php
/**
 * 首页控制器
 * Date: 2025/09/17
 */

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\BaseController;
use App\Services\Admin\HomeService;
use Illuminate\Http\Request;

class HomeController extends BaseController
{
    /**
     * 浏览量概述
     * @date 2025/09/17
     * @return \Illuminate\Http\JsonResponse
     */
    public function overview()
    {
        return (new HomeService())->overview();
    }

    /**
     * 浏览量统计图
     * @date 2025/09/17
     * @param Request $request
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function chart(Request $request)
    {
        $params = $this->validate($request, [
            'type' => 'required|in:1,2',
            'start_time' => 'required',
            'end_time' => 'required'
        ], [
            'type.required' => '查询类型不能为空',
            'type.in' => '查询类型必须为访问次数或者访客数',
            'start_time.required' => '开始时间不能为空',
            'end_time.required' => '结束时间不能为空'
        ]);

        return (new HomeService())->chart($params['type'], $params['start_time'], $params['end_time']);
    }
}
